package com.yeyks.controller.activity;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeyks.activity.dal.domain.ActivityNodeUserRecord;
import com.yeyks.activity.service.ActivityNodeUserRecordService;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.constants.activity.RedisKeyPreConstant;
import com.yeyks.common.em.consumer.UserInviteRelationTypeEnum;
import com.yeyks.common.result.activity.*;
import com.yeyks.commonReference.append.statistic.StatisticBaseService;
import com.yeyks.consumer.service.UserInviteRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "集卡活动统计")
@RestController
@Slf4j
@RequestMapping("/activity/card/stat")
public class ActivityCardStatisticalController {

    @Autowired
    private StatisticBaseService statisticBaseService;
    @Autowired
    private UserInviteRelationService userInviteRelationService;
    @Autowired
    private ActivityNodeUserRecordService activityNodeUserRecordService;

    @ApiOperation(value = "v4.2 --> 活动总统计", response = ActivityCardStatTotalResult.class)
    @PostMapping(value = "/total")
    public AjaxResponseBody<ActivityCardStatTotalResult> total() {
        ActivityCardStatTotalResult result = new ActivityCardStatTotalResult();
        //1:优享首页banner点击量,2:C2B banner点击量,3:活动转发次数,4:活动转发人数,5:免费领卡人数
        result.setVipBannerClickCount(statisticBaseService.statisticCount(RedisKeyPreConstant.STATISTICAL_DATA_MIDDLE_ACTIVITY, RedisKeyPreConstant.ACTIVITY_HOTEL_JIP_INVITE_COUNT, "1"));
        result.setC2bBannerClickCount(statisticBaseService.statisticCount(RedisKeyPreConstant.STATISTICAL_DATA_MIDDLE_ACTIVITY, RedisKeyPreConstant.ACTIVITY_HOTEL_JIP_INVITE_COUNT, "2"));
        result.setForwardTimeCount(statisticBaseService.statisticCount(RedisKeyPreConstant.STATISTICAL_DATA_MIDDLE_ACTIVITY, RedisKeyPreConstant.ACTIVITY_HOTEL_JIP_INVITE_COUNT, "3"));
//        result.setForwardPeopleCount(statisticBaseService.statisticCount(RedisKeyPreConstant.STATISTICAL_DATA_PRE, RedisKeyPreConstant.ACTIVITY_HOTEL_JIP_INVITE_COUNT, "4"));
        int count = activityNodeUserRecordService.count(new QueryWrapper<ActivityNodeUserRecord>()
                .eq(ActivityNodeUserRecord.ACTIVITY_CODE, "activity_hotel_jip_invite").eq(ActivityNodeUserRecord.NODE, "invite_forward"));
        result.setForwardPeopleCount(count);
        return AjaxResponseBody.success(result);
    }

    @ApiOperation(value = "v4.2 --> 免费领卡人数", response = ActivityCardStatResult.class)
    @PostMapping(value = "/get/total")
    public AjaxResponseBody<List<ActivityCardStatResult>> getTotal() {
        //根据activity_code和node查询
        List<ActivityCardStatResult> activityCardStatResults = activityNodeUserRecordService.stat("activity_hotel_jip_invite", "card");
        return AjaxResponseBody.success(activityCardStatResults);
    }

    @ApiOperation(value = "v4.2 --> 活动拉新人数", response = ActivityCardStatResult.class)
    @PostMapping(value = "/new/total")
    public AjaxResponseBody<List<ActivityCardStatResult>> newTotal() {
        List<ActivityCardStatResult> activityCardStatResults = userInviteRelationService.stat(UserInviteRelationTypeEnum.JIP_INVITE_COUNT.getValue());
        return AjaxResponseBody.success(activityCardStatResults);
    }

}
